import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:lishopflu/base/base_import.dart';
import 'package:lishopflu/base/base_list_page.dart';
import 'package:lishopflu/base/view_import.dart';
import 'package:lishopflu/entity/address_bean.dart';

import 'address_choose_ctl.dart';

class AddressChoosePage extends BaseListPage<AddressChooseCtl>{

  @override
  void onCreate(BuildContext mContext) {
    setAppTitle('选择收货地址',);
  }

  @override
  Widget pageBody(BuildContext context) {
    return Column(
      children: [
        Expanded(
          flex: 1,
          child: Obx(() => listBody(context,StaggeredGridView.countBuilder(
            itemBuilder: (BuildContext context, int index){
              return itemBuilder(context, index);
            },
            crossAxisCount: 1,
            mainAxisSpacing: 10.0,
            crossAxisSpacing: 5.0,
            staggeredTileBuilder: (int index) => StaggeredTile.fit(1),/*new StaggeredTile.count(2, index.isEven ? 2 : 1)*/
            itemCount: controller.mList.length,
          ),),),
        ),

        MaterialButton(
          minWidth: double.infinity,
          child: Text('确定', style: TextStyle(color: Colors.white,),),
          color: Colors.blueAccent,
          padding: EdgeInsets.only(top: 8, bottom: 8),
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
          onPressed: (){
            finish(data: AppArguments(obj: controller.addressBean.value));
          },
        ),
      ],
    );
  }

  /// 列表的item
  Widget itemBuilder(BuildContext context, int index){
    AddressBean item = controller.mList[index];
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: ((){
        controller.changeItem(item);
      }),
      child: Container(
        padding: EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10),
        ),
        child: Row(
          children: [
            CircleAvatar(child: Text(item.name.substring(0, 1)),),
            Expanded(
              flex: 1,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Padding(
                        padding: EdgeInsets.only(left: 15, right: 15, top: 5, bottom: 5),
                        child: Text(item.name, style: TextStyle(fontWeight: FontWeight.bold),),
                      ),
                      Text(item.phone),
                    ],
                  ),
                  Padding(
                    padding: EdgeInsets.only(left: 15, right: 15, top: 5, bottom: 5),
                    child: Text(item.address),
                  ),
                ],
              ),
            ),
            Obx(() => Checkbox(
              value: controller.isCheck(item),
              onChanged: (value){
                controller.changeItem(item);
              },
            ),
            ),
          ],
        ),
      ),
    );
  }


}